<?php

namespace App\Http\Model;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

/**
 * 用户首冲奖励记录
 * Class UserFirstRechargeRecord
 * @package App\Http\Model
 */
class UserFirstRechargeRecord extends Base
{
    protected $table = 'user_first_recharge_record';

    protected $primaryKey = 'first_recharge_record_id';

    protected $tablePrefix = 'zb_';


    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);

        $this->tablePrefix = env('DB_PREFIX');
    }

    /**
     * 新增记录首冲
     * @param $data
     * @return mixed
     */
    public function addUserFirstRechargeRecord($data)
    {
        return  DB::table($this->table)->insert($data);
    }

    /**
     * 查某个类型的单条首冲记录
     * @param $userId
     * @param $first_recharge_id
     * @return mixed
     */
    public function findUserFirstRechargeRecord($userId,$first_recharge_id)
    {
        return DB::table($this->table)->where(["first_recharge_id" => $first_recharge_id, "user_id" => $userId])->first();
    }

    /**
     * 查用户首冲记录
     * @param $userId
     * @return mixed
     */
    public function findUserFirstRechargeRecordList($userId)
    {
        return DB::table($this->table)->where(["user_id" => $userId])->get()->toArray();
    }

    /**
     * 查首冲数量
     * @param $userId
     * @return mixed
     */
    public function findUserFirstRechargeRecordCount($userId)
    {
        return DB::table($this->table)->where(["user_id" => $userId])->count();
    }

}

